package com.liebaut.dao.article;

import com.liebaut.model.articles.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ArticleRepository extends JpaRepository<Article, Long> {

    @Query("SELECT a FROM Article a WHERE a.articleNumber = :articleNumber AND a.supplier.number = :supplier")
    List<Article> findByArticleNumberAndSupplier(@Param("articleNumber")String articleNumber, @Param("supplier")int supplier);

    Page<Article> findByArticleNumberLike(String articleNumber, Pageable p);

    @Query("SELECT a FROM Article a WHERE a.supplier.number = :supplier")
    List<Article> findBySupplier(@Param("supplier")int supplier);

    @Query("SELECT  a FROM Article a join a.eanCodes ean WHERE ean.eanCode = :eancode")
    Article findByEanCode(@Param("eancode")int eancode);
}
